<script setup>
import {
    Notebook,
    Promotion,
    UserFilled,
    Document,
    User,
    Basketball,
    Avatar,
    FolderChecked,
    CaretBottom,
    EditPen,
    SwitchButton,
    Search,
    Setting,
    SetUp
} from '@element-plus/icons-vue'
import avatar from '@/assets/to.jpg'
//导入pinia
import {useAdmInfoStore} from '@/stores/adm.js'
import {Userlogout} from '@/api/adm/adm.js'
const admInfoStore = useAdmInfoStore();
import {ElMessage,ElMessageBox} from 'element-plus'
import {useRouter} from 'vue-router'
const router=useRouter();
import { useTokenStore } from '@/stores/token.js'
const tokenStore = useTokenStore()
const handleCommand = (command) => {
    if (command === 'logout') {
        //退出登录
        ElMessageBox.confirm(
            '你确认退出登录吗？',
            '温馨提示',
            {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning',
            }
        )
            .then(async () => {
                //用户点击了确认
                //清空pinia中的token和个人信息
                let result=await Userlogout()
                ElMessage.success(result.data?result.data:"退出成功！")
                admInfoStore.info={}
                tokenStore.token=''
                router.push('/user/login')
            })
            .catch(() => {
                //用户点击了取消
                ElMessage({
                    type: 'info',
                    message: '取消退出',
                })
            })
    } else {
        //路由
        router.push('/' + command)
        console.log(1);
    }
}
</script>

<template>
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <el-menu default-active="/user/index"
                class="el-menu-vertical-demo"
                router>
                <el-menu-item index="/user/index">
                    <el-icon>
                        <Notebook />
                    </el-icon>
                    <span>首页</span>
                </el-menu-item>
                <el-menu-item index="/user/sportsProject">
                    <el-icon>
                        <Promotion />
                    </el-icon>
                    <span>报名运动会</span>
                </el-menu-item>
                <el-menu-item index="/user/sprotsApply">
                    <el-icon>
                        <Promotion />
                    </el-icon>
                    <span>运动会报名表</span>
                </el-menu-item>
                <el-menu-item index="/user/sportsGradue">
                    <el-icon>
                        <Promotion />
                    </el-icon>
                    <span>个人成绩</span>
                </el-menu-item>
                <el-sub-menu >
                    <template #title>
                        <el-icon><Setting /></el-icon>
                        <span>个人中心</span>
                    </template>
                    <el-menu-item index="/user/Info">
                        <el-icon >
                            <User />
                        </el-icon>
                        <span>基本资料</span>
                    </el-menu-item>
                    <el-menu-item index="/user/UpdatePwd">
                        <el-icon>
                            <EditPen />
                        </el-icon>
                        <span>修改密码</span>
                    </el-menu-item>
                </el-sub-menu>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>用户名：<strong>{{ admInfoStore.info.userName ? admInfoStore.info.userName : 'admin' }}</strong></div>
                <el-dropdown placement="bottom-end" @command="handleCommand">
                    <span class="el-dropdown__box">
                        <el-avatar :src="admInfoStore.info.avater ? admInfoStore.info.avater : avatar" />
                        <el-icon>
                            <CaretBottom />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="Info" :icon="User">基本资料</el-dropdown-item>
                            <!-- <el-dropdown-item command="avatar" :icon="Crop">更换头像</el-dropdown-item> -->
                            <!-- <el-dropdown-item command="password" :icon="EditPen">重置密码</el-dropdown-item> -->
                            <el-dropdown-item command="logout" :icon="SwitchButton">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <!-- <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    内容展示区
                </div> -->
                <router-view></router-view>
            </el-main>
            <!-- 底部区域 -->
            <el-footer>高校运动会管理系统 ©2024 Created by 张钦栩</el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;
    .el-aside {
        &__logo {
            height: 120px;
            background: url('@/assets/logo.png')no-repeat center / 120px auto;
        }

        .el-menu {
            border-right: none;
        }
        background:var(--el-menu-bg-color);
    }
    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }
}
</style>